package aobing;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest implements Callable<Integer> {

    static int count;

    public CallableTest(int count) {
        CallableTest.count = count;
    }

    @Override
    public Integer call() throws Exception {
        return count;
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            for(int i = 0;i < 1000;i++){
                count++;
            }
            return count;
        });
        Thread thread = new Thread(futureTask);
        thread.start();
        thread.join();
        Integer total = futureTask.get();
        System.out.println("total = " + total);
    }
}
